﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;
using System.Xml;
using System.Xml.Linq;
using VKontakte;

namespace testApp
{
    public partial class MainPage : UserControl
    {

        APIConnection VK;

        public MainPage()
        {
            InitializeComponent();
            VK = new APIConnection("", MainErrorHendler, true);
        }

        private void send_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                VK.LoadProfile( this.Dispatcher, LoadProfileHandler);                
                //VK.GetPhotoUri("4260162", this.Dispatcher, GetPhotoHendler);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        # region Handlers

        void MainErrorHendler(XDocument error)
        {
            respond.Text += error.ToString();
        }


        void GetPhotoHendler(string response)
        {
            if (response != null)
            {
                respond.Text = response;
            }
        }

        void LoadProfileHandler(Profile response)
        {
            if (response != null)
            {
                MessageBox.Show(response.FirstName + "\r\n" + response.LastName);
            }
        }
        #endregion

    }
}

